<?xml version="1.0" encoding="UTF-8"?>
<cmdbSetting xmlns="http://dctrack.sunbirddcim.com/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="itsm-cmdb.xsd">
	<cmdbType>remedy</cmdbType>
	<pollingInterval>1</pollingInterval>
	<preferences>
		<!-- <dateFormat>yyyy/MM/dd</dateFormat>-->
		<!-- remedy format-->
		<dateFormat>yyyy/MM/dd HH:mm:ss.SSS</dateFormat>
		<unit>US</unit>
		<defaultSystemOfRecord>cmdb</defaultSystemOfRecord>
		<!-- dcim/cmdb -->
		<asset-CmdbInsertPushToDcim>false</asset-CmdbInsertPushToDcim>
		<asset-DcimInsertPushToCmdb>false</asset-DcimInsertPushToCmdb>
		<cmdbPushDataConnectionsToDcim>false</cmdbPushDataConnectionsToDcim>
		<manageDataPorts>false</manageDataPorts>
	</preferences>
	<fieldMappingList>
	
		 <standardField>
			<cmdbFieldId>manufacturer</cmdbFieldId>
			<systemOfRecord>cmdb</systemOfRecord>
			<valueMappings>
                <value>
                    <dcimValue>Cisco Systems</dcimValue>
                    <cmdbValue>Cisco</cmdbValue>
                </value>
            </valueMappings>
			<dcimFieldId>cmbMake</dcimFieldId>		
		</standardField> 
		
		<standardField>
			<cmdbFieldId>model</cmdbFieldId>
			<systemOfRecord>cmdb</systemOfRecord>
			<dcimFieldId>cmbModel</dcimFieldId>
		</standardField>
		
		<standardField>
			<cmdbFieldId>serial</cmdbFieldId>
			<systemOfRecord>cmdb</systemOfRecord>
			<dcimFieldId>tiSerialNumber</dcimFieldId>
		</standardField>
		
		
		<!-- <standardField uniqueKey="true">
			<cmdbFieldId>device</cmdbFieldId>
			<systemOfRecord>cmdb</systemOfRecord>
			<dcimFieldId>tiName</dcimFieldId>
		</standardField> -->
         <standardField uniqueKey="true">
			<cmdbFieldId>name</cmdbFieldId>
			<systemOfRecord>cmdb</systemOfRecord>		
			<dcimFieldId>tiAlias</dcimFieldId>
		</standardField>
		<standardField>
			<!-- we can only map 1:1, but we can choose locations or sites to map to -->
			<cmdbFieldId>site</cmdbFieldId>
			<!-- use location -->
			<systemOfRecord>cmdb</systemOfRecord>
			<valueMappings>
				<value>
					<dcimValue>SITE A</dcimValue>
					<!-- dctrack location -->
					<cmdbValue>SITE A LAB</cmdbValue>
					<!-- netbox location -->
				</value>
			</valueMappings>
			<dcimFieldId>cmbLocation</dcimFieldId>
		</standardField>
		
		<standardField>
			<cmdbFieldId>device_role</cmdbFieldId>
			<systemOfRecord>cmdb</systemOfRecord>
			<dcimFieldId>cmbType</dcimFieldId>
		</standardField>
		
		<standardField>
			<cmdbFieldId>status</cmdbFieldId>
			<systemOfRecord>cmdb</systemOfRecord>
			<valueMappings>
				<value>
					<dcimValue>Installed</dcimValue>
					<cmdbValue>active</cmdbValue>
				</value>
				<value>
					<dcimValue>Planned</dcimValue>
					<cmdbValue>Planned</cmdbValue>
				</value>
				<value>
					<dcimValue>Archived</dcimValue>
					<cmdbValue>offline</cmdbValue>
					<!-- must add a default value -->
					<cmdbValue>decommissioning</cmdbValue>
					<cmdbValue>reset</cmdbValue>
					<cmdbValue>poweroff</cmdbValue>
				</value>
				<value>
					<dcimValue>Storage</dcimValue>
					<cmdbValue>inventory</cmdbValue>
					<cmdbValue>staged</cmdbValue>
				</value>
			</valueMappings>
			<dcimFieldId>cmbStatus</dcimFieldId>
		</standardField>
	</fieldMappingList>
	<!-- ============================= -->
	<!-- DATA PORT SETTINGS START HERE -->
	<!-- ============================= -->
	<fieldMappingList tableType="dataPort" isSplitIp="true">
		<standardField hasChildField="true">
			<cmdbFieldId>data_port</cmdbFieldId>
			<systemOfRecord>cmdb</systemOfRecord>
			<dcimFieldId>tabDataPorts</dcimFieldId>
		</standardField>
		<standardField>
			<cmdbFieldId>portName</cmdbFieldId>
			<systemOfRecord>cmdb</systemOfRecord>
			<dcimFieldId>portName</dcimFieldId>
		</standardField>
		<standardField>
			<cmdbFieldId>portId</cmdbFieldId>
			<systemOfRecord>cmdb</systemOfRecord>
			<dcimFieldId>portId</dcimFieldId>
		</standardField>
		<standardField hasChildField="true">
			<cmdbFieldId>ip_addresses</cmdbFieldId>
			<systemOfRecord>cmdb</systemOfRecord>
			<dcimFieldId>ipAddresses</dcimFieldId>
		</standardField>
		<standardField isIpAssignment="true">
			<cmdbFieldId>ipAddress</cmdbFieldId>
			<systemOfRecord>cmdb</systemOfRecord>
			<dcimFieldId>ipAddress</dcimFieldId>
		</standardField>
		<standardField isIpAssignment="true">
			<cmdbFieldId>cidr</cmdbFieldId>
			<systemOfRecord>cmdb</systemOfRecord>
			<dcimFieldId>cidr</dcimFieldId>
		</standardField>
		<standardField uniqueKey="true">
			<cmdbFieldId>index</cmdbFieldId>
			<systemOfRecord>cmdb</systemOfRecord>
			<dcimFieldId>index</dcimFieldId>
		</standardField>
	</fieldMappingList>
	<!-- ======================================== -->
	<!-- DATA PORT CONNECTION SETTINGS START HERE -->
	<!-- ======================================== -->
	<fieldMappingList tableType="dataConnection">
		<standardField>
			<cmdbFieldId>label</cmdbFieldId>
			<systemOfRecord>cmdb</systemOfRecord>
			<dcimFieldId>cordId</dcimFieldId>
		</standardField>
		<standardField>
			<cmdbFieldId>length</cmdbFieldId>
			<systemOfRecord>cmdb</systemOfRecord>
			<dcimFieldId>cordLength</dcimFieldId>
		</standardField>
		<standardField>
			<!-- Colors -->
			<cmdbFieldId>color</cmdbFieldId>
			<systemOfRecord>cmdb</systemOfRecord>
			<valueMappings>
				<value>
					<dcimValue>Yellow</dcimValue>
					<cmdbValue>ffeb3b</cmdbValue>
				</value>
				<value>
					<dcimValue>Black</dcimValue>
					<cmdbValue>111111</cmdbValue>
				</value>
				<value>
					<dcimValue>White</dcimValue>
					<cmdbValue>ffffff</cmdbValue>
				</value>
			</valueMappings>
			<dcimFieldId>cordColor</dcimFieldId>
		</standardField>
		<standardField>
			<cmdbFieldId>cordType</cmdbFieldId>
			<systemOfRecord>cmdb</systemOfRecord>
			<dcimFieldId>cordType</dcimFieldId>
		</standardField>
	</fieldMappingList>
	<dcimFilters/>
	<cmdbFilters/>
	<!-- ============================= -->
	<!-- OPERATION SETTINGS START HERE -->
	<!-- ============================= -->
	<operationSetting>
		<!-- The dev instance appears to provide timestamp -->
		<lastSyncDateFormat>yyyy-MM-dd'T'HH:mm:ss.SSS'Z'</lastSyncDateFormat>
		<adaptor id="fromQueryDevice">
			<nameField>name</nameField>
			<partnerIdField>id</partnerIdField>
			<add fieldName="site" jsonPath="$.site.name"/>
			<add fieldName="device" jsonPath="$.name"/>
			<add fieldName="name" jsonPath="$.name"/>
			<add fieldName="id" jsonPath="$.id"/>
			<add fieldName="asset_tag" jsonPath="$.asset_tag"/>
			<add fieldName="serial" jsonPath="$.serial"/>
			<add fieldName="manufacturer" jsonPath="$.device_type.manufacturer.name"/>
			<add fieldName="model" jsonPath="$.device_type.model"/>
			<add fieldName="device_role" jsonPath="$.role.name"/>
			<add fieldName="device_type" jsonPath="$.device_type.model"/>
			<add fieldName="asset_tag" jsonPath="$.asset_tag"/>
			<add fieldName="serial" jsonPath="$.serial"/>
			<add fieldName="status" jsonPath="$.status.value"/>
		</adaptor>
		<adaptor id="fromPollingChangedDevicesQuery">
			<nameField>device</nameField>
			<partnerIdField>id</partnerIdField>
			<add fieldName="device" jsonPath="$.name"/>
			<add fieldName="name" jsonPath="$.name"/>
			<add fieldName="id" jsonPath="$.id"/>
			<add fieldName="site" jsonPath="$.site.name"/>
			<add fieldName="model" jsonPath="$.device_type.model"/>
			<add fieldName="asset_tag" jsonPath="$.asset_tag"/>
			<add fieldName="serial" jsonPath="$.serial"/>
		</adaptor>
		<adaptor id="fromPollingChangedIPAddressesQuery">
			<nameField>address</nameField>
			<partnerIdField>id</partnerIdField>
			<add fieldName="address" jsonPath="$.address"/>
			<add fieldName="id" jsonPath="$.id"/>
			<add fieldName="family" jsonPath="$.family.label"/>
			<add fieldName="dnsName" jsonPath="$.dns_name"/>
		</adaptor>
		<adaptor id="fromPollingDataPortsQuery">
			<nameField>device</nameField>
			<partnerIdField>id</partnerIdField>
			<partnerChildIdField type="dataPort">
				<childField isCollection="false">data_port</childField>
				<childIdField>portId</childIdField>
				<add fieldName="portId" jsonPath="$.id"/>
				<add fieldName="portName" jsonPath="$.name"/>
				<add fieldName="index" jsonPath="$.custom_fields.index"/>
				<add fieldName="dataRate" jsonPath="$.type.value"/>
				<add fieldName="comment" jsonPath="$.custom_fields.comment"/>
				<add fieldName="macAddress" jsonPath="$.mac_address"/>
				<add fieldName="userPortName" jsonPath="$.custom_fields.userPortName"/>
				<add fieldName="extStatus" jsonPath="$.custom_fields.extStatus"/>
				<add fieldName="_cmdbEntitySubType">dcim.interface</add>
			</partnerChildIdField>
			<partnerChildIdField type="dataPort">
				<childField isCollection="true" jsonPath="$.id" varJsonPath="$..ipAddresses[?(@.assigned_object_id==${value})]">ip_addresses</childField>
				<add fieldName="_linkedField">data_port</add>
				<add fieldName="ipAddressId" jsonPath="$.id"/>
				<add fieldName="portId" jsonPath="$.assigned_object_id"/>
				<add fieldName="ipAddress" jsonPath="$.address"/>
			</partnerChildIdField>
			<add fieldName="device" jsonPath="$.device.name"/>
			<add fieldName="name" jsonPath="$.device.name"/>
			<add fieldName="id" jsonPath="$.device.id"/>
			<add fieldName="site" jsonPath="$.device.id" varJsonPath="$..devices[?(@.id==${value})].site"/>
			<add fieldName="model" jsonPath="$.device.id" varJsonPath="$..devices[?(@.id==${value})].model"/>
			<add fieldName="status" jsonPath="$.device.id" varJsonPath="$..devices[?(@.id==${value})].status.value"/>
			<add fieldName="serial" jsonPath="$.device.id" varJsonPath="$..devices[?(@.id==${value})].serial"/>
			<add fieldName="asset_tag" jsonPath="$.device.id" varJsonPath="$..devices[?(@.id==${value})].asset_tag"/>
		</adaptor>
		<adaptor id="fromDataConnsQuery">
			<partnerIdField>connectionExtId</partnerIdField>
			<add fieldName="connectionExtId" jsonPath="$.id"/>
			<add fieldName="startingPortExtId" jsonPath="$.a_terminations[0].object.id"/>
			<add fieldName="endingPortExtId" jsonPath="$.b_terminations[0].object.id"/>
			<add fieldName="startingPortExtType" jsonPath="$.a_terminations[0].object_type"/>
			<add fieldName="endingPortExtType" jsonPath="$.b_terminations[0].object_type"/>
			<add fieldName="length" jsonPath="$.length"/>
			<add fieldName="color" jsonPath="$.color"/>
			<add fieldName="label" jsonPath="$.label"/>
			<add fieldName="cordType"><![CDATA[Patch Cord]]></add>
		</adaptor>
		<adaptor id="fromChangedDevicesQuery">
			<nameField>device</nameField>
			<partnerIdField>id</partnerIdField>
			<add fieldName="device" jsonPath="$.name"/>
			<add fieldName="name" jsonPath="$.name"/>
			<add fieldName="id" jsonPath="$.id"/>
			<add fieldName="site" jsonPath="$.site.name"/>
			<add fieldName="model" jsonPath="$.device_type.model"/>
			<updateDateField>updated</updateDateField>
			<updateDateFormat>yyyy-MM-dd'T'HH:mm:ss.SSSZ</updateDateFormat>
		</adaptor>
		
		
		
		<action id="login" logBody="true" logHeader="true">
			<method>POST</method>
			<url><![CDATA[<conf_serviceUrl>/api/users/tokens/provision/]]></url>
			<body><![CDATA[{"username": "<conf_username>", "password": "<conf_password>"}]]></body>
			<contentType>application/json</contentType>
		</action>
		
		<action id="queryDevices" logBody="true" logHeader="true">
			<method>GET</method>
			<url><![CDATA[<conf_serviceUrl>/api/dcim/devices/?last_updated__gt=<lastSyncDate>]]></url>
			<contentType>application/json</contentType>
			<header key="Authorization"><![CDATA[Token <authToken>]]></header>
		</action>
		
		<action id="queryPaginatedDevices" logBody="true" logHeader="true">
			<method>GET</method>
			<url><![CDATA[<_paginateDeviceUrl>]]></url>
			<contentType>application/json</contentType>
			<header key="Authorization"><![CDATA[Token <conf_password>]]></header>
		</action>
		
		<action id="getDeviceRole" logBody="true" logHeader="true">
			<method>GET</method>
			<url><![CDATA[<conf_serviceUrl>/api/dcim/device-roles/?name=<roleName>]]></url>
			<body/>
			<contentType>application/json</contentType>
			<header key="Accept">application/json</header>
			<header key="Authorization"><![CDATA[Token <authToken>]]></header>
		</action>
		
		<action id="createDevice" logBody="true" logHeader="true">
			<method>POST</method>
			<url><![CDATA[<conf_serviceUrl>/api/dcim/devices/]]></url>
			<body><![CDATA[[{"name":"<name>","device_type":{"manufacturer":{"name":"<makeName>"},"model":"<modelName>"},"role":{"name":"<roleName>"},"site":{"name":"<locationName>"},"status":"<itemStatus>","serial":"<serial>","asset_tag":"<asset_tag>"}]]]></body>
			<contentType>application/json</contentType>
			<header key="Authorization"><![CDATA[Token <authToken>]]></header>
		</action>
		
		<action id="updateDevice" logBody="true" logHeader="true">
			<method>PUT</method>
			<url><![CDATA[<conf_serviceUrl>/api/dcim/devices/]]></url>
			<body><![CDATA[[{"id":<partnerId>,"name":"<name>","device_type":{"manufacturer":{"name":"<makeName>"},"model":"<modelName>"},"role":{"name":"<roleName>"},"site":{"name":"<locationName>"},"status":"<itemStatus>","serial":"<serial>"}]]]></body>
			<contentType>application/json</contentType>
			<header key="Authorization"><![CDATA[Token <authToken>]]></header>
		</action>
		
		<action id="queryChangedDataPorts">
			<method>GET</method>
			<url><![CDATA[<conf_serviceUrl>/api/dcim/interfaces/?last_updated__gte=<lastSyncDate>]]></url>
			<contentType>application/json</contentType>
			<header key="Authorization"><![CDATA[Token <authToken>]]></header>
		</action>
		
		<action id="queryPanigatedChangedDataPorts">
			<method>GET</method>
			<url><![CDATA[<_paginateDataPortUrl>]]></url>
			<contentType>application/json</contentType>
			<header key="Authorization"><![CDATA[Token <authToken>]]></header>
		</action>
		
		<action id="queryChangedDataPort">
			<method>GET</method>
			<url><![CDATA[<_dataPortUrl>]]></url>
			<contentType>application/json</contentType>
			<header key="Authorization"><![CDATA[Token <authToken>]]></header>
		</action>
		
		<action id="queryChangedDevices">
			<method>GET</method>
			<url><![CDATA[<conf_serviceUrl>/api/dcim/devices/?id=<_jsonarray_deviceIds>]]></url>
			<contentType>application/json</contentType>
			<header key="Authorization"><![CDATA[Token <authToken>]]></header>
		</action>
		
		<action id="queryChangedIPAddresses">
			<method>GET</method>
			<url><![CDATA[<conf_serviceUrl>/api/ipam/ip-addresses/?interface_id=<_jsonarray_interfaceIds>]]></url>
			<contentType>application/json</contentType>
			<header key="Authorization"><![CDATA[Token <authToken>]]></header>
		</action>
		
		<action id="queryChangedDataConns">
			<method>GET</method>
			<url><![CDATA[<conf_serviceUrl>/api/dcim/cables/?termination_a_type=dcim.interface&last_updated__gte=<lastSyncDate>]]></url>
			<body/>
			<contentType>application/json</contentType>
			<header key="Accept">application/json</header>
			<header key="Authorization"><![CDATA[Token <authToken>]]></header>
		</action>
		
		
<!--		
		<operation id="create">
			<step op="addVar" from="allFields" jsonPath="$.device" varName="name"/>
			<step op="addVar" from="allFields" jsonPath="$.site" varName="locationName"/>
			<step op="addVar" from="allFields" jsonPath="$.status" varName="itemStatus"/>
			<step op="addVar" from="allFields" jsonPath="$.device_role" varName="roleName"/>
			<step action="getDeviceRole"/>
			<step op="addVar" from="body-json" varName="roleName" jsonPath="$.results[0].name"/>
			<step op="addVar" from="allFields" jsonPath="$.manufacturer" varName="makeName"/>
			<step op="addVar" from="allFields" jsonPath="$.model" varName="modelName"/>
			<step op="addVar" from="allFields" jsonPath="$.serial" varName="serial"/>
			<step op="addVar" from="allFields" jsonPath="$.asset_tag" varName="asset_tag"/>
			<step action="createDevice"/>
			<step op="addCi" from="body-json" jsonPath="$" adaptor="fromQueryDevice"/>
		</operation>
-->
<!--		
		<operation id="update">
			<step op="addVar" from="allFields" jsonPath="$.device" varName="name"/>
			<step op="addVar" from="allFields" jsonPath="$.site" varName="locationName"/>
			<step op="addVar" from="allFields" jsonPath="$.status" varName="itemStatus"/>
			<step op="addVar" from="allFields" jsonPath="$.device_role" varName="roleName"/>
			<step op="addVar" from="allFields" jsonPath="$.manufacturer" varName="makeName"/>
			<step op="addVar" from="allFields" jsonPath="$.model" varName="modelName"/>
			<step op="addVar" from="allFields" jsonPath="$.serial" varName="serial"/>
			<step op="addVar" from="allFields" jsonPath="$.asset_tag" varName="asset_tag"/>
			<step op="addVar" from="allFields" jsonPath="$.id" varName="id"/>
			<step action="updateDevice"/>
			<step op="addCi" from="body-json" jsonPath="$" adaptor="fromQueryDevice"/>
		</operation>
		-->
		<operation id="query" maxRunStep="1000000">
		    <step op="addVar" from="value" varName="authToken" ><![CDATA[<conf_password>]]></step>
			<step op="addVar" from="value" varName="lastSyncDate">2025-09-01T10</step>
			<step op="addVar" varName="_paginateDeviceUrl" from="value"><![CDATA[<conf_serviceUrl>/api/dcim/devices/?last_updated__gte=<lastSyncDate>]]></step>
			<step action="queryPaginatedDevices" tag="againPaginatedDevice"/>
			<step op="addCi" from="body-json" jsonPath="$.results" adaptor="fromQueryDevice"/>
			<step op="addVar" varName="_paginateDeviceUrl" from="body-json" jsonPath="$.next" log="true"/>
			<step op="if" varName="_paginateDeviceUrl" is="valid" goto="againPaginatedDevice"/>
		</operation>
<!--		
		<operation id="queryPorts_dataPort" maxRunStep="1000000">
		    <step op="addVar" from="value" varName="authToken" ><![CDATA[<conf_password>]]></step>
			<step op="addVar" from="value" varName="lastSyncDate">2025-09-01T10</step>																			 
			<step op="addVar" varName="_paginateDataPortUrl" from="value"><![CDATA[<conf_serviceUrl>/api/dcim/interfaces/?last_updated__gte=<lastSyncDate>]]></step>
			<step action="queryPanigatedChangedDataPorts" tag="againPaginatedDataPort"/>
			<step op="addVar" from="body-json" jsonPath="$.results[*].device.id" varName="_jsonarray_deviceIds"/>
			<step op="addVar" from="body-json" jsonPath="$.results[*].id" varName="_jsonarray_interfaceIds"/>
			<step op="if" varName="_jsonarray_deviceIds" is="invalid" goto="end"/>
			<step action="queryChangedDevices"/>
			<step op="addAdaptVar" from="body-json" jsonPath="$.results" adaptor="fromPollingChangedDevicesQuery" varName="devices"/>
			<step action="queryChangedIPAddresses"/>
			<step op="addAdaptVar" from="body-json" jsonPath="$.results" adaptor="fromPollingChangedIPAddressesQuery" varName="ipAddresses"/>
			<step action="queryPanigatedChangedDataPorts"/>
			<step op="addCi" from="body-json" jsonPath="$.results" adaptor="fromPollingDataPortsQuery"/>
			<step op="addVar" varName="_paginateDataPortUrl" from="body-json" jsonPath="$.next" log="true"/>
			<step op="if" varName="_paginateDataPortUrl" is="valid" goto="againPaginatedDataPort"/>
			<step tag="end"/>
		</operation>
		
		<operation id="queryDataConn" maxRunStep="1000000">
		    <step op="addVar" from="value" varName="authToken" ><![CDATA[<conf_password>]]></step>
			<step op="addVar" from="value" varName="authToken" ><![CDATA[<conf_password>]]></step>
			<step action="queryChangedDataConns"/>
			<step op="addCi" jsonPath="$.results" adaptor="fromDataConnsQuery"/>
		</operation>
-->		
		<operation id="testConnection">
			<method>POST</method>
			<url><![CDATA[<conf_serviceUrl>/api/users/tokens/]]></url>
			<body/>
			<header key="Authorization">Token <![CDATA[<conf_password>]]></header>>      
	    </operation>
		
	</operationSetting>
</cmdbSetting>